

package dataModifiers;

import inputs.Input;

import java.util.List;
import java.util.Random;

/**
 * RandomInRange Modifier class
 * Extends Modifier functionality
 * 
 * Outputs a random int between Input 0 and Input 1.
 * 		Outputs false if there are not 2 inputs.
 * 
 * @author Dylan James
 *
 */
public class RandomInRange extends Modifier{
	private static Random rn = new Random();
	
	public RandomInRange(List<Input> inputs)
	{
		super(inputs);
	}
	
	@Override
	protected void Initialize() {
	}
	
	@Override
	protected void AccountForInputs() {
		if (inputs.size() >= 2)
		{
			Input input0 = inputs.get(0);
			Input input1 = inputs.get(1);
			
			this.min = (input0.getMin() < input1.getMin()) ? input0.getMin() : input1.getMin();
			this.max = (input0.getMax() < input1.getMax()) ? input1.getMax() : input0.getMin();
		}
		else
		{
			this.min = 0;
			this.max = 0;
		}
	}


	@Override
	protected void Update() {
		if (inputs.size() >= 2){
			int min = inputs.get(0).getValue();
			int max = inputs.get(1).getValue();
			
			if (min > max)
			{
				int tmp = min;
				min = max;
				max = tmp;
			}
			
			this.value = rn.nextInt(max - min) + min;
		}
		else
		{
			this.value = 0;
		}
	}
}
